home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / DISPLAY.ASM < prev    next >
Assembly Source File  |  1995-01-01  |  6KB  |  316 lines

  1. ; DISPLAY for E32 - Copyright (C) 1994 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. ; 11/17/1994: fixed bug causing exception when end of file is at
  5. ; right edge of screen and selector limit = file size
  6. ; also increased speed of clear_to_edge code
  7.  
  8. ; DISPLAY_CURRENT: display current line
  9. ; DISPLAY_SCREEN:  display entire screen
  10.  
  11. include    model.inc
  12.  
  13. public    display_current
  14. public    display_screen, display_bottom
  15. public    display_hex
  16. extrn    dwordtohex:near
  17. extrn    tprint:near, tputchr:near, tprintce:near
  18. extrn    find_start:near
  19. extrn    find_next:near
  20. extrn    topline:near
  21.  
  22. space    equ    20h
  23. CR    equ    0Dh
  24. LF    equ    0Ah
  25. TAB    equ    09h
  26.  
  27. include    dataseg.inc
  28.  
  29. three    db '   ',0
  30. extrn    cursor:dword
  31.  
  32. extrn    top_of_screen:dword
  33. extrn    rows:byte
  34. extrn    dirty_bits:byte
  35. extrn    mark_mode:byte
  36. extrn    mark_start:dword
  37. extrn    mark_end:dword
  38. extrn    cur_posn:word
  39. extrn    normal:byte
  40. extrn    inverse:byte
  41. extrn    filesiz:dword
  42. extrn    columns:byte
  43. extrn    first_row:byte
  44. extrn    left_margin:word
  45. extrn    nul:byte, display_mode:byte
  46.  
  47. margin_count    dw 0
  48.  
  49. display    dd offset display_ascii
  50.     dd offset display_hex
  51.  
  52. @curseg    ends
  53.  
  54. include    codeseg.inc
  55.  
  56. ;
  57. ;  This displays the file buffer on the screen
  58. ;
  59. display_screen    proc    near
  60.     call    topline
  61.     movzx    esi,display_mode
  62.     jmp    display[esi]
  63.  
  64. display_ascii:
  65.     mov    esi,top_of_screen
  66.     mov    dh,first_row
  67.     jmp    short next_row
  68. display_bottom:
  69.     call    find_start
  70.     mov    dx,cur_posn
  71. next_row:
  72.     push    edx
  73.     call    display_line
  74.     pop    edx
  75.     inc    dh
  76.     cmp    dh,rows
  77.     jbe    next_row
  78.     and    dirty_bits,11111110b
  79.     ret
  80. display_screen    endp
  81.  
  82. ;
  83. ; This subroutine displays a single line on the screen.  DH holds the
  84. ; row number, ESI has the offset into the file buffer.  Tabs are expanded.
  85. ; Adjustment is made for side shift.
  86. ;
  87. display_current    proc    near
  88.     call    find_start
  89.     mov    dx,cur_posn
  90. display_line:
  91.     xor    edi,edi        ; default:mark off
  92.     xor    ecx,ecx
  93.     cmp    mark_mode,0
  94.     je    short d1
  95.     mov    edi,mark_start    ; 4-byte mark start
  96.     mov    ecx,mark_end    ; 4-byte mark_end
  97.  
  98. d1:    xor    dl,dl        ; start at column zero
  99.     mov    margin_count,0
  100.     push    fs
  101.     pop    es
  102. next_char:
  103.     cmp    esi,filesiz    ; at end of file?
  104.     jae    short line_done
  105.     mov    al,es:[esi]
  106.     inc    esi
  107.  
  108.     cmp    al,CR        ; is it CR?
  109.     je    short found_CR
  110.     cmp    al,TAB        ; is this a TAB character?
  111.     je    short expand_tab
  112.     call    put_char    ; put character on screen
  113. tab_done:
  114.     cmp    dl,columns    ; at right edge of screen?
  115.     jb    next_char
  116.     cmp    esi,filesiz    ; end of file?
  117.     jae    short line_done
  118.     cmp    byte ptr es:[esi],CR
  119.     je    short not_beyond
  120.     dec    dl
  121.     mov    al,4
  122.     mov    ah,inverse
  123.     call    tputchr
  124. not_beyond:
  125.     jmp    find_next    ; find start of next line
  126. found_CR:
  127.     cmp    esi,filesiz
  128.     jae    short line_done
  129.     mov    al,es:[esi]
  130.     inc    esi
  131.     cmp    al,LF
  132.     je    short line_done
  133.     dec    esi
  134. line_done:
  135.     and    dirty_bits,(not 4)
  136.     jmp    short clear_to_edge    ; erase the rest of the line
  137. expand_TAB:
  138.     mov    al,' '
  139.     call    put_char
  140.     mov    ax,margin_count
  141.     add    al,dl
  142.     test    al,00000111b    ; even multiple of eight?
  143.     jnz    expand_TAB
  144.     jmp    tab_done
  145.  
  146. display_current    endp
  147.  
  148. clear_to_edge:
  149.     push    esi            ; save file pointer
  150.     mov    al,' '
  151.     mov    ah,normal        ; AH = color, AL = character
  152.     cmp    dl,columns        ; don't go past edge of screen
  153.     jae    short clear_done
  154.     lea    esi,nul            ; point to NUL byte
  155.     call    tprintce        ;  just clears to edge of screen
  156. clear_done:
  157.     pop    esi            ; restore file pointer
  158.     ret
  159.  
  160.  
  161. ;
  162. ;  This displays a single character on the screen.  If the
  163. ;  character is marked, it is displayed in reverse video.
  164. ;  Characters outside the current margin are not displayed.
  165. ;  Characters left of the margin are skipped.
  166. ;
  167.  
  168. put_char:
  169.     mov    bx,margin_count
  170.     cmp    bx,left_margin    ; within left margin?
  171.     jae    short in_window    ; yup; show character
  172.     inc    bx
  173.     mov    margin_count,bx
  174.     ret
  175. in_window:
  176.     mov    ah,normal
  177.     cmp    esi,edi        ; before start of marked area?
  178.     jbe    short not_marked
  179.     cmp    esi,ecx        ; after end of marked area?
  180.     ja    short not_marked
  181.     mov    ah,inverse
  182. not_marked:
  183.     call    tputchr        ; update screen
  184.     inc    dl        ; next column
  185.     ret
  186.  
  187.  
  188. ;
  189. ; display file in hex mode
  190. ;
  191. blankspace    equ    [ebp-10]
  192.  
  193. display_hex    proc    near
  194.     push    es
  195.     enter    10,0
  196.     mov    edi,top_of_screen
  197.     push    fs
  198.     pop    es
  199.     xor    edx,edx
  200.     mov    dh,first_row
  201.  
  202. ;
  203. ; start row with near address
  204. ;
  205. row:
  206.     cmp    edi,filesiz
  207.     jae    row4
  208.     lea    esi,blankspace
  209.     mov    eax,edi
  210.     call    dwordtohex
  211.     mov    word ptr 8[esi],':'
  212.     mov    ah,normal
  213.     call    tprint
  214.     add    dl,9
  215.     mov    al,' '
  216.     call    tputchr
  217.     inc    dl
  218.     mov    ecx,16
  219.  
  220. ;
  221. ; print 16 hex bytes
  222. ;
  223.     push    edi            ; save address of start of row
  224. row1:
  225.     cmp    edi,filesiz
  226.     jae    short row2
  227.  
  228.     lea    esi,blankspace
  229.     push    ecx
  230.     movzx    eax,byte ptr es:[edi]
  231.     call    dwordtohex
  232.     mov    byte ptr 8[esi],0
  233.     add    esi,6
  234.     mov    ah,normal
  235.     cmp    mark_mode,0
  236.     je    short row1a
  237.     cmp    edi,mark_start
  238.     jb    short row1a
  239.     cmp    edi,mark_end
  240.     ja    short row1a
  241.     mov    ah,inverse
  242. row1a:
  243.     cmp    edi,cursor
  244.     jne    short row1b
  245.     xor    ah,08h
  246. row1b:
  247.     call    tprint
  248.     add    dl,2
  249.     mov    ah,normal
  250.     mov    al,' '
  251.     call    tputchr
  252.  
  253.     pop    ecx
  254.     inc    dl
  255.     inc    edi
  256.     loop    row1
  257.  
  258. row2:
  259.     inc    ecx
  260.     lea    esi,three
  261.     mov    ah,normal
  262. row3:
  263.     push    ecx
  264.     call    tprint
  265.     add    dl,cl
  266.     pop    ecx
  267.     loop    row3
  268.  
  269.     pop    esi            ; address of start of row
  270.  
  271. ;
  272. ; print ASCII characters at right side of screen
  273. ;
  274.     mov    ecx,16
  275. ascii:
  276.     cmp    esi,filesiz
  277.     jae    short row4
  278.     mov    al,es:[esi]
  279.     mov    ah,normal
  280.     cmp    mark_mode,0
  281.     je    short ascii0
  282.     cmp    esi,mark_start
  283.     jb    short ascii0
  284.     cmp    esi,mark_end
  285.     ja    short ascii0
  286.     mov    ah,inverse
  287. ascii0:
  288.     cmp    esi,cursor
  289.     jne    short ascii1
  290.     xor    ah,08h
  291. ascii1:
  292.     call    tputchr
  293.     inc    esi
  294.     inc    dl
  295.     loop    ascii
  296.  
  297. row4:
  298.     lea    esi,nul
  299.     mov    ah,normal
  300.     call    tprintce
  301.  
  302. ; finished with row; set up for next row
  303.     inc    dh
  304.     xor    dl,dl
  305.     cmp    dh,rows
  306.     jbe    row
  307.  
  308.     leave
  309.     pop    es
  310.     ret
  311.  
  312. display_hex    endp
  313.  
  314. @curseg    ends
  315.     end
  316.